package com.towexin.application.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.towexin.common.ResultData;
import com.towexin.application.system.domain.ExceptionLog;
import com.towexin.application.system.service.ExceptionLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * TODO
 *
 * @author Towexin
 * @version 1.0
 * @date 2021/7/29 11:37
 */
@RestController
@RequestMapping("exception-log")
public class ExceptionLogController {
    @Autowired
    private ExceptionLogService service;

    @GetMapping("page")
    @RequiresPermissions("system.exception-log.list")
    public ResultData selectPage(int page, int limit){
        return ResultData.OK(service.page(new Page<>(page, limit), new QueryWrapper<ExceptionLog>().orderByDesc("created_time")));
    }

    @GetMapping("clear")
    @RequiresPermissions("system.exception-log.clear")
    public ResultData clearLog(){
        return service.remove(null)?ResultData.OK():ResultData.NO();
    }

}
